package com.blog.effective.note5;

import java.util.Date;
import java.util.HashSet;

/**
 * 避免创建不必要的对象.
 *
 * @author 张俊强~.
 * @date 2017/11/1-20:50.
 */
public class NecessaryObjectDemo {

    public static void main(String[] args) {

        HashSet hs=new HashSet();

        Date s=new Date();
        long time=10000000;
//        long count=0L;      //运行三次花费时间：14ms 12ms 13ms
        Long count=0L;    //运行三次花费时间：114ms 83ms 79ms
        for (long i = 0; i < time; i++) {
            count++;
        }
        Date e=new Date();
        System.out.println((e.getTime() - s.getTime())+"ms");
    }
}
